package com.dlyk.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.dlyk.DlykServerApplication;
import com.dlyk.bean.TDicValue;
import com.dlyk.result.DicEnum;

import java.util.List;

/**
 * 状态转换器
 */
public class StatusConverter implements Converter<Integer> {
    // 转换为java对象
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {

        String cellStatusName = cellData.getStringValue();
        List<TDicValue> dicValueList = (List<TDicValue>) DlykServerApplication.cacheMap.get(DicEnum.STATE.getCode());

        for (TDicValue tDicValue : dicValueList) {
            Integer id = tDicValue.getId();
            String name = tDicValue.getTypeValue();

            if (cellStatusName.equals(name)){
                return id;
            }
        }
        return -1;
    }
}
